using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace GatoRatoQueijo
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        KeyboardState keyboard;
        GamePadState gamePad;

        Bringel bringel;
        Cleber cleber;
        Objeto2D background;

        public static Game1 Self;

        int lastSeconds;

        public Game1()
        {
            Self = this;
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.PreferredBackBufferWidth = 1024;
            graphics.PreferredBackBufferHeight = 768;
            //graphics.ToggleFullScreen();
            graphics.ApplyChanges();
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            bringel = new Bringel(Content.Load<Texture2D>("cleber"), Window, null, 0.2f);
            bringel.setarPontoDeReferencia(Objeto2D.PontoDeReferencia.CENTRO);
            bringel.drawCollisionBounds = true;
            cleber = new Cleber(Content.Load<Texture2D>("cleber"), Window, null, 0.19f);
            cleber.setarPontoDeReferencia(Objeto2D.PontoDeReferencia.CENTRO);
            background = new Objeto2D(Content.Load<Texture2D>("grama"), null, 0.01f);
            
          //  carta = new Carta(Content.Load<Texture2D>("magic"), Window);
            
        }

        protected override void UnloadContent()
        {
            
        }

        protected override void Update(GameTime gameTime)
        {

            

            keyboard = Keyboard.GetState();
            gamePad = GamePad.GetState(PlayerIndex.One);

            Missile.Update(gameTime);
            bringel.update(keyboard, gamePad);
            cleber.update(gameTime, new Vector2(bringel.x, bringel.y));

            if ((gameTime.TotalGameTime.Seconds - lastSeconds) >= 1)
                Carta.criarCarta(Content.Load<Texture2D>("magic"), Window);

            lastSeconds = gameTime.TotalGameTime.Seconds;            

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);

                background.draw(gameTime, spriteBatch);
                Carta.Draw(gameTime, spriteBatch);
                bringel.draw(gameTime, spriteBatch);
                cleber.draw(gameTime, spriteBatch);
                Missile.Draw(gameTime, spriteBatch);
                //background.alpha = 0.2f;

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
